<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            padding:0;
            margin:0;
            border:0 none;
        }
        .box{
            width: 600px;
            margin:100px auto;
        }
        input{
            width: 480px;
            height: 40px;
            padding-left:20px;
            border:1px solid orange;
        }
        ul{
            display: none;
            width: 500px;
            border:1px solid orange;
        }
        li{
            width: 480px;
            padding-left:20px;
            list-style:none;
            height: 50px;
            font:700 16px/50px microsoft yahei;
        }
    </style>
</head>
<body>
<div class="box">
    <input type="text" value="请选择字体">
    <ul>
        <li>宋体</li>
        <li>黑体</li>
        <li>楷体</li>
        <li>微软雅黑</li>
        <li>新宋体</li>
        <li>仿体</li>
    </ul>
</div>
<script>
    var inp=document.getElementsByTagName("input")[0];
    var oUl=document.getElementsByTagName("ul")[0];
    var links=oUl.getElementsByTagName("li");
    //此处的onfocus为什么出现闪退现象
    inp.onclick=function(ev){
        ev=ev||event;
        oUl.style.display="block";
        inp.value="";
        ev.cancelBubble=true;
        for(var i=0;i<links.length;i++){
            links[i].onmouseover=function(){
                this.style.backgroundColor="orange";
                this.style.color="#fff";
            }
                links[i].onmouseout=function(){
                if(inp.value!==this.innerHTML){
                    this.style.backgroundColor="#fff";
                    this.style.color="#000";
                }
             }
            links[i].onclick=function(ev){
                ev=ev||event;
                for(var j=0;j<links.length;j++){
                    links[j].style.backgroundColor="#fff";
                    links[j].style.color="#000";
                }
                inp.value=this.innerHTML;
                this.style.backgroundColor="orange";
                this.style.color="#fff";
                ev.cancelBubble=true;

            }
        }
    }
    document.onclick=function(){
        oUl.style.display="none";
        if(!inp.value){
            inp.value="请选择字体";
        }
    }
</script>
</body>
</html>